import { ExceptionFilter, Catch, ArgumentsHost, HttpException} from '@nestjs/common';
import httpException from './exceptions';

@Catch(...httpException)
export class HttpExceptionFilter implements ExceptionFilter {
  catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse();
    const request = ctx.getRequest();
    const status = exception.getStatus();
    console.log(exception.message)
    console.log(exception.name)
    
    response.status(status).json({
      statusCode: exception.getStatus(),
      timestamp: new Date().toISOString(),
      path: request.url,
      msg: exception.message.message
    })
  }
}